package db_main

import (
	"errors"
	"fmt"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/const"
	utils2 "longmen/server/pkg/common/helper/util"
	"strings"

	"gorm.io/gorm"
)

func CheckBannedlive(uId int) (int, error) {
	fName := "CheckBannedlive"
	banTime := -1
	err := global.GetR().Table("db_anchor_banned").Select("ban_time").Where("anchor_id", uId).Find(&banTime).Error
	if err != nil && (errors.Is(err, gorm.ErrRecordNotFound) || strings.Contains(err.Error(), _const.MSG_NOT_FOUND)) {
		err = nil
	}
	if err != nil {
		return banTime, fmt.Errorf("%s%s", utils2.Convert(fName), err.Error())
	}
	return banTime, nil
}
